const { lessorsModel } = require('./models/lessorsModel')

module.exports.getLessors = async function () {
    return await lessorsModel.find()
}
// 登录
module.exports.loginLessors = async function (item) {
    const result = await lessorsModel.findOne(item);
    return result;
}

// 禁用
module.exports.frozenLessors = async function (item) {
    const result = await lessorsModel.updateOne({ _id: item._id }, { state: item.state });
    return result;
}

//注册
module.exports.registerLessors = async function (item) {
    const result = await lessorsModel.create(item);
    return result;
}

//注册判断
module.exports.isLessors = async function (item) {
    const result = await lessorsModel.find(item);
    return result;
}
// 获取所有的出租人数据
// module.exports.getLessors = async function () {
//     const result = await lessorsModel.find();
//     return result;
// }

module.exports.getLessors = async function ({pagesize,currentpage}) {
    const result = await lessorsModel.find().limit(pagesize-0).skip((currentpage-1)*pagesize);
    const total = await lessorsModel.countDocuments()
    console.log({pagesize,currentpage});
    console.log(result);
    return {result,total};
}

// 获取对应用户的ID
module.exports.getTokenData = async function (item) {
    const result = await lessorsModel.findOne(item);
    return result;
}
